﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using coliseu.BussinessLayer;

namespace coliseu
{
    public partial class FrmCadBloco : Form
    {
        private BlocoBL bl;
        private bloco blE;

        public FrmCadBloco(BlocoBL bl)
        {
            InitializeComponent();
            this.bl = bl;
            blocoBindingSource.AddNew();
        }

        public FrmCadBloco(BlocoBL bl, bloco blE)
        {
            InitializeComponent();
            this.bl = bl;
            this.blE = blE;

            textBox1.Enabled = false;
            blocoBindingSource.DataSource = blE;
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void FrmCadBloco_Load(object sender, EventArgs e)
        {

        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            blocoBindingSource.EndEdit();

            if(blE == null)
                bl.salvar((bloco)blocoBindingSource.Current, "insert");
            else
                bl.salvar((bloco)blocoBindingSource.Current, "edit");

            MessageBox.Show("Salvo com sucesso", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Close();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
